// 注册cloud ui
import { type PluginManager } from '/@/views/formDesigner/utils';
import Input from './normar/input';
import InputSelect from './normar/inputSelect';
import Card from './normar/card';
import Row from './normar/row';
import Col from './normar/col';
// import Cascader from './normar/cascader';
import Switch from './normar/switch';
import Textarea from './normar/textarea';
import Radio from './normar/radio';
import Checkbox from './normar/checkbox';
import Select from './normar/select';
import TreeSelect from './normar/tree-select';
import colorPicker from './normar/color-picker';
import InputNumber from './normar/input-number';
import Button from './normar/button';
import DatePicker from './normar/date-picker';
import Calc from './normar/calc';
import Form from './normar/form';
import FormItem from './normar/form-item';
import Divider from './normar/divider';
import Modal from './common/modal';

import { Macro } from './macro';

// import LenSize from './common/lenSize';
// import CalcInput from './common/calcInput';
// import MacroIconCtl from './common/macroIconCtl';
// import MacroFormulaCtl from './common/macroFormulaCtl';
// import NestSheet from './common/nestSheet';
// import ModuleFieldSelect from './common/moduleFieldSelect';

export function setupCloud(pluginManager: PluginManager) {
  // 异步加载组件
  pluginManager.component('Collapse', async () => await import('ant-design-vue/lib/collapse'));
  pluginManager.component(
    'CollapseItem',
    async () => await import('ant-design-vue/lib/collapse/CollapsePanel'),
  );
  pluginManager.component('Tabs', async () => await import('ant-design-vue/lib/tabs'));
  pluginManager.component('TabPane', async () => (await import('ant-design-vue/lib/tabs')).TabPane);

  // console.log('Macro', Macro);
  const MacroList: any = [];
  const MacroListName: any = [];
  for (const v in Macro) {
    MacroList.push(Macro[v]);
    MacroListName.push(Macro[v].defaultSchema.type);
  }
  console.log('MacroList', MacroList);
  console.log('MacroListName', MacroListName);
  const componentArray = [
    Input,
    InputSelect,
    // Cascader,
    Switch,
    Textarea,
    Radio,
    Checkbox,
    Select,
    Card,
    Row,
    colorPicker,
    InputNumber,
    Button,
    Col,
    Form,
    FormItem,
    DatePicker,
    Calc,
    Modal,
    Divider,
    // LenSize,
    // CalcInput,
    // MacroIconCtl,
    // MacroFormulaCtl,
    // NestSheet,
    // ModuleFieldSelect,
    TreeSelect,
    ...MacroList,
  ];

  componentArray.forEach((item) => {
    pluginManager.registerComponent(item);
  });
  console.log('注册组件', pluginManager.getComponents());

  // 设置分组显示
  pluginManager.setSchemaGroup([
    {
      title: '常规',
      list: [
        'input',
        'textarea',
        'select',
        'radio',
        'checkbox',
        'date',
        'button',
        'calc',
        // 'cascader',
        // 'switch',
        // 'color-picker',
        // 'number',
      ],
    },
    {
      title: '宏控件',
      list: [...MacroListName],
    },
    {
      title: '布局',
      list: ['card', 'row'],
    },
  ]);
}
